Shader "Unlit/NewUnlitShader"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _SpecPower("SpecPower", Range(1,128)) = 1
        _SpecIntensity("SpecInstensity", Color) = "1,1,1,1"
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
          //  #pragma multi_compile_fog

            #include "UnityCG.cginc"
            #include "Lighting.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
              //  float2 uv : TEXCOORD0;
                half n : NORMAL;
            };

            struct v2f
            {
            //    float2 uv : TEXCOORD0;
           //     UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
                float3 posWorld : TEXCOORD0;
                half n : NORMAL;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float4 _SpecIntensity;
            float _SpecPower;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.n = UnityObjectToWorldNormal(v.n);
                o.posWorld = mul(unity_ObjectToWorld, v.vertex);  //将顶点转换到世界坐标
               // o.uv = TRANSFORM_TEX(v.uv, _MainTex);
             //   UNITY_TRANSFER_FOG(o,o.vertex);
                
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                //环境光
                fixed4 col = unity_AmbientSky;

                //漫反射光
                float3 n = normalize(i.n);
                float3 l = _WorldSpaceLightPos0;
                float fDiff =  max(dot(n,l),0);
                col += fDiff * _LightColor0;

                //镜面光
                float3 r = reflect(-1,n); //面试题 ，内部实现 以及性能如何
                float3 e = normalize(_WorldSpaceCameraPos - i.posWorld);
                float fSpec = pow(max(0,dot(r,e)),_SpecPower);
                col += _SpecIntensity * fSpec;
                
                return col;
            }
            ENDCG
        }
    }
}
